<template>
  <div>
    <TopFilter :list="partLossList" :cols="3" :labelWidth="90" @filterChange="changeHandle"></TopFilter>
    <FilterTable
      ref="partTable"
      :columns="partLossColumns"
      :isSelectColumn="false"
      :dataSource="listResult"
      :datakey="'rows'"
      :onColumnsChange="columns => this.partLossColumns = columns"
    >
      <template slot="controls">
        <el-button size="small" type="primary">导出</el-button>
      </template>
    </FilterTable>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
export default {
  name: 'partLoss',
  mixins: [dictionary],
  data() {
    this.BaseTable = null;
    return {
      partLossList: this.createPartInfoFilterList(),
      // fetchApi:'',
      // fetchParams: { xhrAbort: false },
      listResult:[],
      partLossColumns: this.createPartColumns()
    };
  },

  methods: {
    createPartInfoFilterList() {
      return [
        {
          type: 'SELECT',
          label: '仓库',
          fieldName: 'STORAGE_CODE',
          itemList: []
        },
        {
          type: 'INPUT',
          label: '配件代码',
          fieldName: 'PART_NO'
        },
        {
          type: 'RANGE_DATE',
          label: '日期',
          fieldName: 'beginDate|endDate',
          valueFormat: 'yyyy-MM-dd'
        }
      ];
    },
    createPartColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '仓库',
          dataIndex: 'STORAGE_CODE',
          sorter: true
        },
        {
          title: '库位',
          dataIndex: 'STORAGE_POSITION_CODE',
          sorter: true
        },
        {
          title: '配件代码',
          dataIndex: 'PART_NO',
          sorter: true
        },
        {
          title: '配件名称',
          dataIndex: 'PART_NAME',
          sorter: true
        },
        {
          title: '计量单位',
          dataIndex: 'UNIT_CODE',
          sorter: true
        },
        {
          title: '库存数量',
          dataIndex: 'STOCK_QUANTITY',
          sorter: true
        },
        {
          title: '成本单价',
          dataIndex: 'COST_PRICE',
          sorter: true
        },
        {
          title: '盘亏金额',
          dataIndex: 'LOSS_QUANTITY',
          sorter: true
        },
        {
          title: '报损数量',
          dataIndex: 'LOSS_AMOUNT',
          sorter: true
        },
        {
          title: '报溢金额',
          dataIndex: 'PROFIT_AMOUNT',
          sorter: true
        },
        {
          title: '报溢数量',
          dataIndex: 'PROFIT_QUANTITY',
          sorter: true
        }
      ];
    },
    changeHandle(val) {
      console.log('val', val);
      this.fetchParams = Object.assign({}, val, { xhrAbort: false });
    }
  },
  mounted() {
    this.BaseTable = this.$refs.partTable.$refs.pageTable;
    let list={
      STORAGE_CODE:'OEM库',
      STORAGE_POSITION_CODE:'C-01-01-13',
      PART_NO:'1F1Z7F404AA',
      PART_NAME:'轴承',
      UNIT_CODE:'个',
      STOCK_QUANTITY:782.00,
      COST_PRICE:164.10,
      LOSS_QUANTITY:0.00,
      LOSS_AMOUNT:0.00,
      PROFIT_AMOUNT:465.76,
      PROFIT_QUANTITY:15.00
    }
   this.listResult=[list]
  }
};
</script>

<style scoped lang="less">
</style>
